package com.activemq;

import java.util.Map;

import javax.jms.JMSException;

import org.apache.activemq.command.ActiveMQObjectMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

@Component  
public class LogConsumer {  
  
    private static final Logger LOGGER = LoggerFactory.getLogger(LogConsumer.class);  
  
    @JmsListener(destination = "sample.queue")  //,containerFactory="jmsListenerContainerQueue"
    public void receivedQueue(String msg) {  
        LOGGER.info("Has received from LOG, 队列消息: " + msg);  
    }
    
    @JmsListener(destination = "sample.topic",containerFactory="jmsListenerContainerTopic")
    public void receivedTopic(Object msg) {
    	try {
			ActiveMQObjectMessage mqMsg = (ActiveMQObjectMessage)msg;
			@SuppressWarnings("unchecked")
			Map<String,Object> m = (Map<String,Object>)mqMsg.getObject();
			LOGGER.info(m.toString());
			/*User user = (User)mqMsg.getObject();
			LOGGER.info("Has received from LOG, 订阅消息: " + user.getName() + " - " + user.getPassword() + " - " + user.getCreateTime());*/
		} catch (JMSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}  
    }
}
